package cn.yangsen.simplebeanmanager.bean.html;

import lombok.Getter;
import lombok.Setter;
import cn.yangsen.simplebeanmanager.tool.HtmlTool;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;

@XStreamAlias("script")
@XStreamConverter(value=ToAttributedValueConverter.class, strings={"content"})
public class Script extends Element
{
	@Setter
	@Getter
	@XStreamAsAttribute
	private String type;
	
	@Setter
	@Getter
	@XStreamAsAttribute
	private String src;
	
	@Getter
	@Setter
	private String content = " ";
	
	public void addContent(String newS)
	{
		if(content.equals(" "))
		{
			content = newS;
		}
		else
		{
			content = content + newS;
		}
	}
	
	/**
	 * 由于js脚本非标准的xml文件，其内容中包含了“<”等符号。所以需要转码。
	 * js脚本不能包含换号，因为其换行有意义
	 */
	@Override
	public String toHtml()
	{
		String s = super.toHtml();
		s= HtmlTool.字符实体转预留字段(s);
		s = s.replace("\n", "");
		return s;
	}
}
